/**
 * Created by easy on 15/5/15.
 */
//提交类型
//1新增异常
//2编辑异常
//3添加异常备注
//4编辑异常备注
//5添加订单备注
//6添加流程备注
//7编辑流程备注
$(document).ready(function () {
    var params = mc.getParamsFromURL(window.location);
    var setName = function (name) {
        return name.split(".")[0]
    };
    vars.submitType = parseInt(params.submitType);
    vars.type = parseInt(params.type);// 备注类型
    vars.objID = params.objID;
    vars.orderID = params.orderID;
    $(".textcolor-process").text(params.processName);
    var placeholderText = "";
    switch (vars.submitType) {
        case 1 ://新增流程异常

        case 2 ://编辑异常
            placeholderText = "请填写异常描述...";

            break;
        case 3 ://添加异常备注
        case 4 ://编辑异常备注
            placeholderText = "请填写异常备注...";
            break;
        case 5 ://添加订单备注
            placeholderText = "请填写备注...";
            break;
        case 6 ://添加流程备注
        case 7 ://编辑流程备注
            vars.orderID = params.orderID;
            placeholderText = "请填写流程备注...";
            $(".submit-progress").show();
            break;
        case 8 ://回复
            vars.toUserID = params.toUserID;
            vars.toUserName = params.toUserName;
            placeholderText = "请填写备注回复...";
            break;
        default :
            placeholderText = "请填写内容...";
            break;
    }
    vars.submitPhotos = new Ractive({
        el: "CONTAINER-photo",
        template: "#TEMPLATE-photo",
        data: {ractiveData: [], setName: setName}
    })
    //$(".description-textarea").attr("placeholder", placeholderText)
});
(function () {
    vars.submitPhotosArray = [];
    vars.submitPhotosKeyArray = [];
    basic.deviceReady = function () {
        if (!vars.userInfo) {
            mc.getUserInfo(function (data) {
                vars.userInfo = JSON.parse(data);
            })
        }
        $("#processName").show();
        if (vars.submitType == 2 || vars.submitType == 4) {
            mc.getDataFromLocalStorage("submitData", function (data) {
                vars.jsonPK = data.jsonPK;
                vars.content = data.descriptionEdit ? data.descriptionEdit : data.description;
                vars.orderID = data.orderID;
                vars.status = data.status;
                $("#submitContent").text(vars.content);
                vars.submitPhotosKeyArray = data.attachment && data.attachment != "null" && data.attachment != "[]" ? JSON.parse(data.attachment) : [];

                vars.submitPhotos.data.ractiveData = vars.submitPhotosKeyArray;
                vars.submitPhotos.update("ractiveData");
                common.showPhotos([data]);
                mc.showContent();
            }, "app");
        } else if (vars.submitType == 7) {
            var params = mc.getParamsFromURL(window.location);
            mc.getDataFromLocalStorage("submitData", function (data) {
                vars.jsonPK = data.jsonPK;
                vars.content = data.description;
                vars.quantity = data.completeQuantity;
                vars.orderID = params.orderID;
                vars.processID = params.processID;
                $("#submitContent").text(vars.content);
                $(".input-finishnumber").val(vars.quantity);
                mc.showContent();
            }, "app");
        } else {
            mc.showContent();
        }

    };
    util.showSubmitPhotosByIndex = function (currIndex) {
        var data = vars.submitPhotos.data.ractiveData;
        var photoKeyArray = [];
        for (var i = 0; i < data.length; i++) {
            photoKeyArray.push(data[i]);
        }
        mc.showPhotosByIndex(photoKeyArray, currIndex);
    }
    util.rightButtonEventCallback = function () {
        //alert("右侧按钮点击")
        util.submit();
    };
    document.addEventListener('rightButtonEvent', util.rightButtonEventCallback, false);
    util.leftButtonEventCallback = function () {
        //alert("左侧按钮点击")
        mc.backToPrePage();
    };
    document.addEventListener('leftButtonEvent', util.leftButtonEventCallback, false);

    // 添加图片
    util.addPhoto = function () {
        /*var obj = document.getElementById("addPhoto");
         obj.options[0].selected = true;*/
        var addPhotoCallback = function (data) {
            //alert(JSON.stringify(data));
            if (data.length == undefined) {
                data = [data];
            }
            var length = data.length;
            for (var i = 0; i < length; i++) {
                //alert(i)
                var photoItem = data[i];
                //alert(JSON.stringify(photoItem))
                vars.submitPhotosKeyArray.push(photoItem.originalFileKey);
                vars.submitPhotosArray.push(photoItem);
            }
            //alert(vars.submitPhotosKeyArray.length)
            vars.submitPhotos.data.ractiveData = vars.submitPhotosKeyArray;
            vars.submitPhotos.update("ractiveData");
            for (var i in data) {
                var photoItem = data[i];
                var id = photoItem.thumbnailFileKey.replace("96x96_", "");
                $("#" + id.split(".")[0]).attr("src", photoItem.thumbnailFilePath);
            }
        };
        mc.myFileChooser(addPhotoCallback);
    };

    util.removePhoto = function (val) {
        Array.prototype.arrayIndexOf = function (val) {
            for (var i = 0; i < this.length; i++) {
                var key = this[i].originalFileKey?this[i].originalFileKey:this[i];
                if (key == val) return i;
            }
            return -1;
        };
        Array.prototype.removeByValue = function (val) {
            var index = this.arrayIndexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };
        vars.submitPhotosKeyArray.removeByValue(val);
        vars.submitPhotosArray.removeByValue(val);
        vars.submitPhotos.data.ractiveData = vars.submitPhotosKeyArray;
        vars.submitPhotos.update("ractiveData");
    }

    vars.inTheSubmit = false;
    util.submit = function () {
        var submitContent = $("#submitContent").val();
        if (vars.submitPhotosKeyArray.length == 0 && !submitContent) {
            mc.alert("请输入文字内容或添加图片!", function () {
            });
            return;
        }
        if (vars.inTheSubmit == false) {
            vars.inTheSubmit = true;
        } else {
            return false
        }
        var submitCallback = function (data) {
            if (data.result == true) {
                mc.backToPrePage()
            } else {
                vars.inTheSubmit = false;
            }
        };
        var params;
        switch (vars.submitType) {
            case 1:
                params = util.addProcessAbnormal(submitContent);
                break;
            case 2:
                params = util.updateAbnormal(submitContent);
                break;
            case 3:
                params = util.addAbnormalRemark(submitContent);
                break;
            case 4:
                params = util.updateAbnormalRemark(submitContent);
                break;
            case 5:
                params = util.addProcessRemark(submitContent);
                break;
            case 6:
                /*var finishNumber = $(".input-finishnumber").val();
                 if (finishNumber == 0 || finishNumber == "") {
                 alert("请填写完成数量");
                 return;
                 }*/
                params = util.addProcessRemark(submitContent);
                break;
            case 7:
                var finishNumber = $(".input-finishnumber").val();
                if (finishNumber == 0 || finishNumber == "") {
                    mc.alert("请填写完成数量");
                    return;
                }
                params = util.updateSubProcessRemark(submitContent, finishNumber);
                break;
            case 8:
                params = util.addRemarkReply(submitContent);
                break;
        }
        mc.submitToAjaxWorker(params, submitCallback);
    }

    util.updateAbnormal = function (submitContent) {
        var requestData = {
            "keyID": vars.jsonPK,
            "description": submitContent,
            "userID": vars.userInfo.userID,
            "attachment": vars.submitPhotosKeyArray
        };
        console.log(JSON.stringify(requestData));
        var extraData = {
            "person": vars.userInfo.username,
            "action": "修改了一条异常",
            "content": [{"text": submitContent}],
            "photos": vars.submitPhotosArray
        };
        //alert(vars.submitPhotosKeyArray)
        var time = new Date().getTime();
        //提交前向主数据异常表 修改指定异常
        var SQLOfUpdateAbnormal = "UPDATE QC_ABNORMAL SET description = '" + submitContent + "' , descriptionEdit = '" + submitContent + "' ,lastModifiedByUserLogin = '" + vars.userInfo.username + "'," +
            "lastUpdateTime='" + time + "',attachment='" + JSON.stringify(vars.submitPhotosKeyArray) + "', descriptionStatus = ?,attachmentStatus = ?,attachmentEdit = '" + JSON.stringify(vars.submitPhotosKeyArray) + "' WHERE jsonPK = '" + vars.jsonPK + "';";

        //提交后修改异常状态
        var SQLOfChangeAbnormalStatus = "UPDATE QC_ABNORMAL SET descriptionStatus = ?, attachmentStatus = ? WHERE jsonPK = '" + vars.jsonPK + "';";

        //提交前后 修改订单表状态
        var SQLOfChangeOrderStatus = "UPDATE QC_ORDER SET lastUpdateTime = '" + time + "', abnormalStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.orderID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.orderID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END WHERE jsonPK = '" + vars.orderID + "';";

        //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
        var params = {
            URL: service.url + "/updateAbnormal",
            HTTPMethod: "post",
            requestData: requestData,
            extra: extraData,
            uploadAttachmentFilesInfo: vars.submitPhotosArray,
            matchIDs: vars.jsonPK + "," + vars.orderID,
            SQLOperation: {
                SQLOfAjaxStarted: SQLOfUpdateAbnormal + SQLOfChangeOrderStatus,
                SQLOfAjaxCompleted: SQLOfChangeAbnormalStatus + SQLOfChangeOrderStatus
            },
            noticePages: ["abnormal.html", "abnormal-detail.html", "orders.html", "dynamic.html"]
        };
        return params;
    }

    util.updateAbnormalRemark = function (submitContent) {
        var time = new Date().getTime();
        var requestData = {
            "id": vars.jsonPK,
            "description": submitContent,
            "lastModifiedByUserLogin": vars.userInfo.username,
            "attachment": vars.submitPhotosKeyArray
        };
        var extraData = {
            "person": vars.userInfo.username,
            "action": "修改了一条异常备注",
            "content": [{"text": submitContent}],
            "photos": vars.submitPhotosArray
        };
        //提交前向主数据异常表 修改指定异常
        var SQLOfUpdateAbnormalRemark = "UPDATE QC_REMARK SET description = '" + submitContent + "' ,descriptionEdit = '" + submitContent + "' ,lastModifiedByUserLogin = '" + vars.userInfo.username + "'," +
            "lastUpdateTime='" + time + "',attachment='" + JSON.stringify(vars.submitPhotosKeyArray) + "',descriptionStatus = ?,attachmentStatus = ?,attachmentEdit = '" + JSON.stringify(vars.submitPhotosKeyArray) + "' WHERE jsonPK = '" + vars.jsonPK + "';";

        //提交后修改异常状态
        var SQLOfChangeAbnormalRemarkStatus = "UPDATE QC_REMARK SET descriptionStatus = ?,attachmentStatus=? WHERE jsonPK = '" + vars.jsonPK + "';";

        //提交前后 修改订单表状态
        var SQLOfChangeAbnormalStatus = "UPDATE QC_ABNORMAL SET lastUpdateTime = '" + time + "',lastModifiedByUserLogin = '" + vars.userInfo.username + "', remarkStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END WHERE jsonPK = '" + vars.objID + "';";

        //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
        var params = {
            URL: service.url + "/remark/updateRemark",
            HTTPMethod: "post",
            requestData: requestData,
            extra: extraData,
            uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
            matchIDs: vars.jsonPK + "," + vars.objID,
            SQLOperation: {
                SQLOfAjaxStarted: SQLOfUpdateAbnormalRemark + SQLOfChangeAbnormalStatus,
                SQLOfAjaxCompleted: SQLOfChangeAbnormalRemarkStatus + SQLOfChangeAbnormalStatus
            },
            noticePages: ["abnormal.html", "orders.html", "dynamic.html", "abnormal-detail.html"]
        };
        return params;
    }

    util.updateSubProcessRemark = function (submitContent, finishNumber) {
        var time = new Date().getTime();
        var requestData = {
            "id": vars.jsonPK,
            "localPK": "remark_" + time,
            "objID": vars.processID,
            "completeQuantity": finishNumber,
            "description": submitContent,
            "createdByUserLogin": vars.userInfo.username,
            "attachment": vars.submitPhotosKeyArray,
            "type": vars.type
        };
        var extraData = {
            "person": vars.userInfo.username,
            "action": "修改了一流程备注",
            "content": [{"text": "流程：" + submitContent}, {"text": mc.dealTime(time, "yyyy--MM-dd") + "   完成" + finishNumber + "双"}],
            "photos": vars.submitPhotosArray
        };
        //提交前向主数据异常表 修改指定异常
        var SQLOfUpdateProcessRemark = "UPDATE QC_REMARK SET description = '" + submitContent + "', descriptionEdit = '" + submitContent + "' ,completeQuantityEdit = '" + finishNumber + "',lastModifiedByUserLogin = '" + vars.userInfo.username + "'," +
            "lastUpdateTime='" + time + "',attachment='" + JSON.stringify(vars.submitPhotosKeyArray) + "',descriptionStatus = ?,completeQuantityStatus = ? WHERE jsonPK = '" + vars.jsonPK + "';";

        //前向主数据动态表 插入一条到全部历史
        /* var SQLOfInsertRemarkToDynamic = "INSERT INTO QC_DYNAMIC " +
         "(jsonPK, matchID, description, createdName,lastUpdateTime, attachment, createStatus, type) VALUES" +
         " ('remark" + time + "', '" + vars.jsonPK + "', '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?,1 );";
         */
        //提交后修改异常状态
        var SQLOfChangePorcessRemarkStatus = "UPDATE QC_REMARK SET descriptionStatus = ?,completeQuantityStatus = ? WHERE jsonPK = '" + vars.jsonPK + "';";

        //提交前后 修改流程表状态
        var SQLOfChangeProcessStatus = "UPDATE QC_PROCESS SET remarkStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.processID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.processID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END WHERE jsonPK = '" + vars.processID + "';";

        //提交前后 修改订单表状态
        var SQLOfChangeOrderStatus = "UPDATE QC_ORDER SET processStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.orderID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.orderID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END WHERE jsonPK = '" + vars.orderID + "';";

        //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
        var params = {
            URL: service.url + "/remark/updateRemark",
            HTTPMethod: "post",
            requestData: requestData,
            extra: extraData,
            uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
            matchIDs: vars.processID + "," + vars.orderID,
            SQLOperation: {
                SQLOfAjaxStarted: SQLOfUpdateProcessRemark + SQLOfChangePorcessRemarkStatus + SQLOfChangeOrderStatus + SQLOfChangeProcessStatus,
                SQLOfAjaxCompleted: SQLOfChangePorcessRemarkStatus + SQLOfChangeProcessStatus + SQLOfChangeOrderStatus
            },
            noticePages: ["detail.html", "sub-process.html", "orders.html", "dynamic.html"]
        };
        return params;
    }

    util.addProcessRemark = function (submitContent) {
        var time = new Date().getTime();
        var requestData = {
            "localPK": "remark_" + time,
            "orderID": vars.orderID,
            "objID": vars.objID,
            "description": submitContent,
            "userID": vars.userInfo.userID,
            //"completeQuantity": quantity,
            "attachment": vars.submitPhotosKeyArray,
            "type": vars.type
        };
        console.log(JSON.stringify(requestData));
        var extraData = {
            "person": vars.userInfo.username,
            "action": "添加了一条流程备注",
            "content": [{"text": submitContent}],//{"text": "完成了" + quantity + "双"},
            "photos": vars.submitPhotosArray
        };
        //提交前向主数据备注表 插入一条备注
        var SQLOfInsertNewRemark = "INSERT INTO QC_REMARK " +
            "(localPK, objID, orderID, description, createdByUserLogin,lastUpdateTime, attachment, createStatus, type, unread) VALUES" +
            " ('remark_" + time + "', '" + vars.objID + "','" + vars.orderID + "', '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?," + vars.type + ",'F');";

        //提交后修改备注状态
        var SQLOfChangeNewRemarkStatus = "UPDATE QC_REMARK SET createStatus = ? WHERE localPK = 'remark_" + time + "';";

        //完成后修改本地新增數據jsonPK
        var SQLUpdateNewRemarkJsonPK = "UPDATE QC_REMARK SET jsonPK = ? WHERE localPK = 'remark_" + time + "';";
        //jsonPK冲突后删除本地数据
        var SQLRemoveNewRemark = "DELETE FROM  QC_REMARK WHERE localPK = 'remark_" + time + "';";

        //提交前后 修改订单表状态
        var SQLOfChangeProcessStatus = "UPDATE QC_PROCESS SET lastUpdateTime = '" + time + "',lastModifiedByUserLogin = '" + vars.userInfo.username + "', remarkStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END WHERE jsonPK = '" + vars.objID + "';";

        //var SQLOfChangeOrderStatus = "
        // UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
        var params = {
            URL: service.url + "/add/addProcessRemark",
            //URL: service.url + "/add/addRemark",
            HTTPMethod: "POST",
            requestData: requestData,
            extra: extraData,
            uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
            matchIDs: vars.objID,
            SQLOperation: {
                SQLOfAjaxStarted: SQLOfInsertNewRemark + SQLOfChangeProcessStatus,
                SQLOfAjaxCompleted: SQLOfChangeNewRemarkStatus + SQLOfChangeProcessStatus,
                SQLOfAjaxSuccess: ";",
                SQLOfAjaxException: ";"
            },
            noticePages: ["detail.html", "orders.html", "dynamic.html", "process-detail.html"]
        };
        return params;
    }

    /*    util.addSubProcessRemark = function (submitContent, finishNumber) {
     var time = new Date().getTime();
     var requestData = {
     "localPK": "remark_" + time,
     "objID": vars.objID,
     "completeQuantity": finishNumber,
     "description": submitContent,
     "createdByUserLogin": vars.userInfo.username,
     "lastUpdateTime": time,
     "attachment": vars.submitPhotosArray,
     "type": vars.type
     };
     var extraData = {
     "person": vars.userInfo.username,
     "action": "添加了一流程备注",
     "content": [{"text": "流程：" + submitContent}, {"text": mc.dealTime(time, "yyyy-MM-dd") + "   完成" + finishNumber + "双"}],
     "photos": vars.submitPhotosArray
     };
     //提交前向主数据备注表 插入一条备注
     var SQLOfInsertNewRemark = "INSERT INTO QC_REMARK " +
     "(localPK, jsonPK, objID, completeQuantity, description, createdByUserLogin,lastUpdateTime, attachment, createStatus, type) VALUES" +
     " ('remark_" + time + "','remark_" + time + "', '" + vars.objID + "', " + finishNumber + ", '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?," + vars.type + " );";

     //前向主数据动态表 插入一条备注
     */
    /*var SQLOfInsertNewRemarkToDynamic = "INSERT INTO QC_DYNAMIC " +
     "(localPK, jsonPK, matchID, description, createdName,lastUpdateTime, attachment, createStatus, type) VALUES" +
     " ('remark_" + time + "', 'remark_" + time + "', '" + vars.objID + "', '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?,1 );";
     */
    /*
     //提交后修改备注状态
     var SQLOfChangeNewRemarkStatus = "UPDATE QC_REMARK SET createStatus = ? WHERE jsonPK = 'remark_" + time + "';";

     //提交前后 修改订单表状态
     var SQLOfChangeOrderStatus = "UPDATE QC_ORDER SET processStatus = CASE " +
     "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.orderID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
     "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.orderID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
     "ELSE 'success' END WHERE jsonPK = '" + vars.orderID + "';";

     //提交前后 修改流程表状态
     var SQLOfChangeProcessStatus = "UPDATE QC_PROCESS SET remarkStatus = CASE " +
     "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
     "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
     "ELSE 'success' END WHERE jsonPK = '" + vars.objID + "';";

     //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
     var params = {
     URL: service.url + "/remark/insertRemark",
     HTTPMethod: "PUT",
     requestData: requestData,
     extra: extraData,
     uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
     matchIDs: vars.objID + "," + vars.orderID,
     SQLOperation: {
     SQLOfAjaxStarted: SQLOfInsertNewRemark + SQLOfChangeOrderStatus + SQLOfChangeProcessStatus,
     SQLOfAjaxCompleted: SQLOfChangeNewRemarkStatus + SQLOfChangeOrderStatus + SQLOfChangeProcessStatus
     },
     noticePages: ["detail.html", "sub-process.html", "orders.html", "dynamic.html"]
     };
     return params;
     }*/

    /*util.addAbnormalRemark = function (submitContent) {
     var time = new Date().getTime();
     var requestData = {
     "objID": vars.objID,
     "description": submitContent,
     "userID": vars.userInfo.userID,
     "attachment": vars.submitPhotosKeyArray,
     "type": vars.type
     };

     var extraData = {
     "person": vars.userInfo.username,
     "action": "添加了一条异常备注",
     "content": [{"text": submitContent}],
     "photos": vars.submitPhotosArray
     };
     //提交前向主数据备注表 插入一条备注
     var SQLOfInsertNewRemark = "INSERT INTO QC_REMARK " +
     "(localPK, objID, description, createdByUserLogin,lastUpdateTime, attachment, createStatus, type, attachmentStatus, attachmentEdit) VALUES" +
     " ('remark_" + time + "','" + vars.objID + "', '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?," + vars.type + ",?,'" + JSON.stringify(vars.submitPhotosKeyArray) + "');";

     //提交后修改备注状态
     var SQLOfChangeNewRemarkStatus = "UPDATE QC_REMARK SET createStatus = ?,attachmentStatus = ? WHERE localPK = 'remark_" + time + "';";

     //提交前后 修改异常表状态
     var SQLOfChangeAbnormalStatus = "UPDATE QC_ABNORMAL SET lastUpdateTime = '" + time + "',lastModifiedByUserLogin = '" + vars.userInfo.username + "',remarkStatus = CASE " +
     "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
     "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
     "ELSE 'success' END WHERE jsonPK = '" + vars.objID + "';";
     //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
     var params = {
     URL: service.url + "/add/insertRemark",
     HTTPMethod: "POST",
     requestData: requestData,
     extra: extraData,
     uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
     matchIDs: vars.objID,
     SQLOperation: {
     SQLOfAjaxStarted: SQLOfInsertNewRemark + SQLOfChangeAbnormalStatus,
     SQLOfAjaxCompleted: SQLOfChangeNewRemarkStatus + SQLOfChangeAbnormalStatus
     },
     noticePages: ["abnormal.html", "orders.html", "dynamic.html", "abnormal-detail.html"]
     };
     return params;
     }*/

    util.addRemarkReply = function (submitContent) {
        var time = new Date().getTime();
        var requestData = {};
        var SQLOfInsertNewRemark = "";
        if (vars.toUserID) {
            requestData = {
                "localPK": "remark_" + time,
                "objID": vars.objID,
                "userID": vars.userInfo.userID,
                "description": submitContent,
                //"createdByUserLogin": vars.userInfo.username,
                "attachment": vars.submitPhotosKeyArray,
                "type": vars.type,
                "toUserID": vars.toUserID
            };
            //提交前向主数据备注表 插入一条备注
            SQLOfInsertNewRemark = "INSERT INTO QC_REMARK " +
            "(localPK, objID, description, descriptionEdit, createdByUserLogin, lastUpdateTime, attachment, createStatus, toUserID, toUserName, type) VALUES" +
            " ('remark_" + time + "','" + vars.objID + "','" + submitContent + "', '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?,'" + vars.toUserID + "','" + vars.toUserName + "',3);";
        } else {
            requestData = {
                "localPK": "remark_" + time,
                "objID": vars.objID,
                "userID": vars.userInfo.userID,
                "description": submitContent,
                "attachment": vars.submitPhotosKeyArray,
                "type": vars.type
            };
            //提交前向主数据备注表 插入一条备注
            SQLOfInsertNewRemark = "INSERT INTO QC_REMARK " +
            "(localPK, objID, description, descriptionEdit, createdByUserLogin, lastUpdateTime, attachment, createStatus, type, unread) VALUES" +
            " ('remark_" + time + "','" + vars.objID + "', '" + submitContent + "','" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?," + vars.type + ",'F');";
        }
        ;

        var extraData = {
            "person": vars.userInfo.username,
            "action": "回复了一条异常备注",
            "content": [{"text": submitContent}],
            "photos": vars.submitPhotosArray
        };
        //提交后修改备注状态
        var SQLOfChangeNewRemarkStatus = "UPDATE QC_REMARK SET createStatus = ? WHERE localPK = 'remark_" + time + "';";

        //服务端数据返回后修改本地新增數據的jsonPK
        var SQLUpdateNewRemarkJsonPK = "UPDATE QC_REMARK SET jsonPK = ? WHERE localPK = 'remark_" + time + "';";
        //jsonPK冲突后删除本地数据
        var SQLRemoveNewRemark = "DELETE FROM  QC_REMARK WHERE localPK = 'remark_" + time + "';";

        //提交前后 修改异常表状态
        var SQLOfChangeAbnormalStatus = "UPDATE QC_REMARK SET lastUpdateTime = '" + time + "',lastModifiedByUserLogin = '" + vars.userInfo.username + "',remarkStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END,lastUpdateTime = '" + time + "' WHERE jsonPK = '" + vars.objID + "';";
        //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
        var params = {
            URL: service.url + "/add/addRemarkReply",
            HTTPMethod: "POST",
            requestData: requestData,
            extra: extraData,
            uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
            matchIDs: vars.objID,
            SQLOperation: {
                SQLOfAjaxStarted: SQLOfInsertNewRemark + SQLOfChangeAbnormalStatus,
                SQLOfAjaxCompleted: SQLOfChangeNewRemarkStatus + SQLOfChangeAbnormalStatus,
                SQLOfAjaxSuccess: ";",
                SQLOfAjaxException: ";"
            },
            noticePages: ["abnormal.html", "orders.html", "dynamic.html", "abnormal-detail.html"]
        };
        return params;
    }

    util.addProcessAbnormal = function (submitContent) {
        var time = new Date().getTime();
        //alert(vars.submitPhotosKeyArray)
        var requestData = {
            "localPK": "abnormal_" + time,
            "orderID": vars.orderID,
            "processID": vars.objID,
            "userID": vars.userInfo.userID,
            "description": submitContent,
            //"createdByUserLogin": vars.userInfo.username,
            "attachment": vars.submitPhotosKeyArray,
            "status": "1",
            "completeRate": "0%"
        };
        var extraData = {
            "person": vars.userInfo.username,
            "action": "添加了一条流程异常",
            "content": [{"text": submitContent}],
            "photos": vars.submitPhotosArray
        };
        //提交前向主数据备注表 插入一条备注
        var SQLOfInsertNewAbnormal = "INSERT INTO QC_ABNORMAL " +
            "(localPK, processID, orderID, description, createdByUserLogin,lastUpdateTime, attachment,attachmentEdit,attachmentStatus, createStatus, status,completeRate, unread) VALUES" +
            " ('abnormal_" + time + "', '" + vars.objID + "','" + vars.orderID + "', '" + submitContent + "','" + vars.userInfo.username + "','" + time + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "','" + JSON.stringify(vars.submitPhotosKeyArray) + "',?,?,'进行中','0%' ,'F');";

        //服务端数据返回后修改本地新增數據的jsonPK
        var SQLUpdateNewAbnormalJsonPK = "UPDATE QC_ABNORMAL SET jsonPK = ? WHERE localPK = 'abnormal_" + time + "';";
        //jsonPK冲突后删除本地数据
        var SQLRemoveNewAbnormal = "DELETE FROM  QC_ABNORMAL WHERE localPK = 'abnormal_" + time + "';";

        //提交后修改备注状态
        var SQLOfChangeNewAbnormalStatus = "UPDATE QC_ABNORMAL SET createStatus = ?,attachmentStatus = ? WHERE localPK = 'abnormal_" + time + "';";

        //提交前后 修改订单表状态
        var SQLOfChangeProcessStatus = "UPDATE QC_PROCESS SET lastUpdateTime = '" + time + "',lastModifiedByUserLogin = '" + vars.userInfo.username + "', abnormalStatus = CASE " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'uploading') > 0) THEN 'uploading' " +
            "WHEN ((SELECT count(1) FROM T_CloudDataTransferCenter WHERE FCloudDataTransferMatchIDs LIKE '%" + vars.objID + "%' AND FCloudDataTransferState = 'failed') > 0) THEN 'failed' " +
            "ELSE 'success' END WHERE jsonPK = '" + vars.objID + "';";

        //var SQLOfChangeOrderStatus = "UPDATE tab_Order SET remark_status = 'test1111' WHERE json_pk = '"+vars.orderID+"';";
        var params = {
            URL: service.url + "/add/addProcessAbnormal",
            HTTPMethod: "POST",
            requestData: requestData,
            extra: extraData,
            uploadAttachmentFilesInfo: vars.submitPhotosArray ? vars.submitPhotosArray : [],
            matchIDs: vars.objID + "," + vars.orderID,
            SQLOperation: {
                SQLOfAjaxStarted: SQLOfInsertNewAbnormal + SQLOfChangeProcessStatus,
                SQLOfAjaxCompleted: SQLOfChangeNewAbnormalStatus + SQLOfChangeProcessStatus,
                SQLOfAjaxSuccess: ";",
                SQLOfAjaxException: ";"
            },
            noticePages: ["detail.html", "orders.html", "dynamic.html", "abnormal.html", "process-detail.html"]
        };
        return params;
    }
})();